<?php
/**
 * Created by PhpStrom
 * User: 郭碧云
 * Date: 2021/7/12 17:35
 * Desc:
 */

namespace App\Http\Validations\Admin;


use App\Service\QuestionTypeService;
use Illuminate\Contracts\Validation\Validator;

class QuestionTypeValidation
{
    public function create() {
        return [
            'rules' => [
                "name"=>["required",
                    function ($attribute, $value, $fail) {
                        $info = (new QuestionTypeService())->first(["name"=>$value,"site_id"=>getCurrentSiteId()]);
                        if (!empty($info)) {
                            $fail("分类名称已存在");
                        }
                    },],

                "type"=>"required"
            ],
            'attributes' => [
                "name"=>"分类名称",
                "type"=>"题型分类"
            ],
            'messages' => [
                "name"=>"必须存在",
                "type"=>"必须存在"
            ]
        ];
    }

    public function update(){
        return [
            'rules' => [
                "type"=>"required"
            ],
            'attributes' => [
                "type"=>"题型分类"
            ],
            'messages' => [
                "type"=>"必须存在"
            ]
        ];
    }

    public function checkId(){
        return [
            'rules' => [
                "id"=>"required|min:1|integer",
            ],
            'attributes' => [
                "id"=>"编号",
            ],
            'messages' => [
                "id"=>"必须是正整数",
            ]
        ];
    }

    //验证后添加的钩子函数
    public function customValidate(Validator $validator) {
        //
    }
}
